package cn.codergege.springmvc.service.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.codergege.springmvc.dao.EmployeeMapper;
import cn.codergege.springmvc.model.Employee;
import cn.codergege.springmvc.service.EmployeeService;

@Service("employeeService")
public class EmployeeServiceImpl implements EmployeeService {
	private final Logger log = LoggerFactory.getLogger(EmployeeServiceImpl.class);
	@Autowired
	private EmployeeMapper employeeMapper;

	@Override
	public List<Employee> getAll() throws Exception {
		log.info("----> getting all employees");
		return employeeMapper.getAll();
	}

	@Override
	public int add(Employee employee) throws Exception {
		log.info("----> adding an employee: " + employee);
		return employeeMapper.insertSelective(employee);
	}

	@Override
	public int delete(int id) throws Exception {
		log.info("----> deleting an employee, id: " + id);
		return employeeMapper.deleteByPrimaryKey(id);
	}

	@Override
	public Employee getById(int id) throws Exception {
		log.info("----> get an employee, id: " + id);
		return employeeMapper.selectByPrimaryKey(id);
	}

	@Override
	public int update(Employee employee) throws Exception {
		log.info("----> update employee: " + employee);
		return employeeMapper.updateByPrimaryKeySelective(employee);
	}

}
